//
//  NoteBottomView.m
//  NanNote
//
//  Created by 郑楠 on 15/5/20.
//  Copyright (c) 2015年 ___NANteam___. All rights reserved.
//

#import "NoteBottomView.h"

#define WIDTH self.frame.size.width
#define HEIGHT self.frame.size.height

@interface NoteBottomView ()

// 调整字体大小按钮
@property(nonatomic, retain)UIButton *fontSizeBtn;
// 调整note颜色按钮
@property(nonatomic, retain)UIButton *noteColorBtn;
// 发送mail按钮
@property(nonatomic, retain)UIButton *shareBtn;
// 地图按钮
@property(nonatomic, retain)UIButton *locationBtn;
// 照相机按钮
@property(nonatomic, retain)UIButton *cameraBtn;
// 回收键盘按钮
@property(nonatomic, retain)UIButton *returnKeyBoardBtn;

@end

@implementation NoteBottomView

-(instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // 调整字体大小按钮
        self.fontSizeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.fontSizeBtn setBackgroundImage:[UIImage imageNamed:@"font.png"] forState:UIControlStateNormal];
        self.fontSizeBtn.frame = CGRectMake(5, 5, 30, 30);
        [self.fontSizeBtn addTarget:self action:@selector(fontSizeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.fontSizeBtn];
        // 背景颜色
        self.noteColorBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.noteColorBtn setBackgroundImage:[UIImage imageNamed:@"color.png"] forState:UIControlStateNormal];
        self.noteColorBtn.frame = CGRectMake(40, 5, 30, 30);
        [self.noteColorBtn addTarget:self action:@selector(noteColorBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.noteColorBtn];
        // 分享
        self.shareBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.shareBtn setBackgroundImage:[UIImage imageNamed:@"share.png"] forState:UIControlStateNormal];
        self.shareBtn.frame = CGRectMake(75, 5, 30, 30);
        [self.shareBtn addTarget:self action:@selector(shareBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.shareBtn];
        // 照相按钮
        self.cameraBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.cameraBtn setBackgroundImage:[UIImage imageNamed:@"camera.png"] forState:UIControlStateNormal];
        self.cameraBtn.frame = CGRectMake(110, 5, 30, 30);
        [self.cameraBtn addTarget:self action:@selector(cameraBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.cameraBtn];
        // 地图按钮
        self.locationBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.locationBtn setBackgroundImage:[UIImage imageNamed:@"location.png"] forState:UIControlStateNormal];
        self.locationBtn.frame = CGRectMake(145, 5, 30, 30);
        [self.locationBtn addTarget:self action:@selector(locationBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.locationBtn];
        // 回收键盘
        self.returnKeyBoardBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.returnKeyBoardBtn setTitle:@"OK" forState:UIControlStateNormal];
        self.returnKeyBoardBtn.frame = CGRectMake(180, 5, 30, 30);
        [self.returnKeyBoardBtn addTarget:self action:@selector(returnKeyBoardBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.returnKeyBoardBtn];
    }
    
    return self;
}
// 改变字体大小
- (void)fontSizeBtnClick:(UIButton *)fontSizeBtn {
    UIActionSheet *fontOfSizeActionSheet = [[UIActionSheet alloc] initWithTitle:@"字体大小" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"小", @"中", @"大", nil];
    [fontOfSizeActionSheet showInView:self.superview];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    // 选择字体的actionsheet
    if ([actionSheet.title isEqualToString:@"字体大小"]) {
        if (buttonIndex == 0) {
            [self.delegate changeNoteFontSize:@"16"];
        } else if (buttonIndex == 1) {
            [self.delegate changeNoteFontSize:@"18"];
        } else if (buttonIndex == 2) {
            [self.delegate changeNoteFontSize:@"22"];
        }
    // 图片actionSheet
    } else if ([actionSheet.title isEqualToString:@"图片选择"]){
        // 为了点取消时候取消,所以写的只有点第一个,第二个时候做操作
        if (buttonIndex == 0) {
            [self.delegate imageChooseBtnClick:buttonIndex];
        } else if (buttonIndex == 1) {
            [self.delegate imageChooseBtnClick:buttonIndex];
        }
    }
}

// 改变背景颜色
- (void)noteColorBtnClick:(UIButton *)noteColor {
    [self.delegate changeNoteBgColor:@""];
}
// 分享
- (void)shareBtnClick:(UIButton *)shareBtn {
    [self.delegate shareBtnClick];
}
// 添加图片
- (void)cameraBtnClick:(UIButton *)cameraBtn {
    UIActionSheet *cameraActionSheet = [[UIActionSheet alloc] initWithTitle:@"图片选择" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照", @"相册", nil];
    [cameraActionSheet showInView:self.superview];
}
// 添加地点
- (void)locationBtnClick:(UIButton *)locationBtn {
    
}

- (void)returnKeyBoardBtnClick {
    [self.delegate doneBtnClick];
}
@end
